import { _decorator, Component, Node } from 'cc';
import { EVENT_NAMES } from '../../../../utils/Enums';
import { Label } from 'cc';
import Config from '../../../../utils/Config';
const { ccclass, property } = _decorator;

@ccclass('InfoPanel')
export class InfoPanel extends Component {
    @property({ type: Node, displayName: "锤子道具提示标签" })
    rotateNode: Node;
    
    @property({ type: Node, displayName: "交换道具提示标签" })
    exchangeRemindNode: Node;
    
    @property({ type: Label, displayName: "倒计时标签" })
    countdownLabel: Label;

    start() {
        this.initListener()
    }
    
    protected onDestroy(): void {
        gg.systemEvent.off(EVENT_NAMES.SET_CLICKED_BRECK_REMIND, this.setClickBrickRemind, this)
        gg.systemEvent.off(EVENT_NAMES.SET_CLICKED_EXCHANGE_REMIND, this.setClickExchangeRemind, this)
        gg.systemEvent.off(EVENT_NAMES.UPDATE_COUNTDOWN, this.panelUpdate, this)
    }
    
    // ----------------- 初始化 ----------------- //
    private initListener() {
        gg.systemEvent.on(EVENT_NAMES.SET_CLICKED_BRECK_REMIND, this.setClickBrickRemind, this)
        gg.systemEvent.on(EVENT_NAMES.SET_CLICKED_EXCHANGE_REMIND, this.setClickExchangeRemind, this)
        gg.systemEvent.on(EVENT_NAMES.UPDATE_COUNTDOWN, this.panelUpdate, this)
    }

    // ----------------- 事件 ----------------- //
    private setClickBrickRemind(state: boolean) {
        this.rotateNode.active = state
    }
    
    private setClickExchangeRemind(state: boolean) {
        this.exchangeRemindNode.active = state
    }

    // 倒计时
    private panelUpdate(dt: number) {
        this.countdownLabel.string = Config.formatCountdown(dt)
    }
}


